/**
 * 验证链接名称不为空
 */
function checkLName(){
	var LName = $.trim($("#lname").val());
	var falg = true;
	if(LName == null || LName == "" || LName == "链接名称"){
		layer.tips("请输入链接名称", "#lname", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证链接地址不为空
 */
function checkLPath(){
	var LPath = $.trim($("#lpath").val());
	var falg = true;
	if(LPath == null || LPath == "" || LPath == "链接地址"){
		layer.tips("请输入链接地址", "#lpath", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证链接说明不为空
 */
function checkLdes(){
	var Ldes = $.trim($("#ldes").val());
	var falg = true;
	if(Ldes == null || Ldes == "" || Ldes == "链接说明"){
		layer.tips("请输入链接说明", "#ldes", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 用户申请友情链接
 */
function addLink(){
	if(checkLName()&&checkLPath()&&checkLdes()){
		var lname = $.trim($("#lname").val());
		var lpath = $.trim($("#lpath").val());
		var ldes = $.trim($("#ldes").val());
		$.ajax({
			type : "post",
			url : "/link/addUserLink",
			async : false,
			data : {
				lname : lname,
				lpath : lpath,
				ldes:ldes
			},
			dataType:"json",
			success : function(data){
				if(data.code== 0){
					layer.msg(data.msg, {icon: 6}, function(){
						location.href =  "/index.html";
					});
				}else if(data.code==500){
					layer.msg(data.msg, {icon: 5});
				}
				
			}
		});
	}
}
//回车触发登录
function keyLogin(e){
	  var theEvent = window.event || e;
	      var code = theEvent.keyCode || theEvent.which;
	   if (code==13) {  //回车键的键值为13
		   addLink();  //调用提交登录
	   }
	  }